package com.gs.gaosheng.controller;

import com.gs.common.annotation.Log;
import com.gs.common.core.controller.BaseController;
import com.gs.common.core.domain.AjaxResult;
import com.gs.common.core.page.TableDataInfo;
import com.gs.common.enums.BusinessType;
import com.gs.common.utils.poi.ExcelUtil;
import com.gs.gaosheng.domain.GsAdress;
import com.gs.gaosheng.service.GsAdressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 收货地址Controller
 *
 * @author yy
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/gaosheng/adress")
public class GsAdressController extends BaseController
{
    @Autowired
    private GsAdressService gsAdressService;

    /**
     * 查询收货地址列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GsAdress gsAdress)
    {
        startPage();
        List<GsAdress> list = gsAdressService.selectGsAdressList(gsAdress);
        return getDataTable(list);
    }

    /**
     * 导出收货地址列表
     */
    @Log(title = "收货地址", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GsAdress gsAdress)
    {
        List<GsAdress> list = gsAdressService.selectGsAdressList(gsAdress);
        ExcelUtil<GsAdress> util = new ExcelUtil<GsAdress>(GsAdress.class);
        return util.exportExcel(list, "adress");
    }

    /**
     * 获取收货地址详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gsAdressService.selectGsAdressById(id));
    }

    /**
     * 新增收货地址
     */
    @Log(title = "收货地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GsAdress gsAdress)
    {
        return toAjax(gsAdressService.insertGsAdress(gsAdress));
    }

    /**
     * 修改收货地址
     */
    @Log(title = "收货地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GsAdress gsAdress)
    {
        return toAjax(gsAdressService.updateGsAdress(gsAdress));
    }

    /**
     * 删除收货地址
     */
    @Log(title = "收货地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gsAdressService.deleteGsAdressByIds(ids));
    }
}
